$(function () {
  // 親メニュー処理
  
  $('span.news_span').click(function() {
    // メニュー表示/非表示
    $(this).toggleClass('active');
    $(this).next('ul').slideToggle('fast');
  });

});

$(function () {
  // 親メニュー処理
  
  $('span.top_box_span').click(function() {
    // メニュー表示/非表示
    $(this).toggleClass('active');
    $(this).next('.top_box_open').slideToggle('normal');
  });

});
/*#133 Start Luvina Modify*/
$(function () {
  // 親メニュー処理
  
  $('.mypage_list .title.sp').click(function() {
    // メニュー表示/非表示
    $(this).toggleClass('active');
    $(this).next('.mypage_list .main').slideToggle('normal');
  });

});
/*#133 End Luvina Modify*/

//求人情報×
$(function () {
     $("#head_recruit .close").click(function(){
         $(this).parents("#head_recruit").animate({ opacity: "hide" }, "slow");
         setCookie("flg_head_recruit_pc", 1, 30);
     });
     var flgHidden = getCookie("flg_head_recruit_pc");
     if (flgHidden != null && flgHidden != "" && flgHidden == 1) {
         $("#head_recruit").hide();
     }
});
//求人情報SP×
$(function () {
     $(".recruit_area_sp .close").click(function(){
         $(this).parents(".recruit_area_sp").animate({ opacity: "hide" }, "slow");
         setCookie("flg_head_recruit_sp", 1, 30);
     });
     var flgHidden = getCookie("flg_head_recruit_sp");
     if (flgHidden != null && flgHidden != "" && flgHidden == 1) {
         $("#head_recruit_sp").hide();
     }
});


function DropDown(el) {
    this.dd = el;
    this.opts = this.dd.find('ul.dropdown > li');
    this.val = [];
    this.index = [];
    this.initEvents();
}
DropDown.prototype = {
    initEvents : function() {
        var obj = this;

        obj.dd.on('click', function(event){
            $(this).toggleClass('active');
            event.stopPropagation();
        });

        obj.opts.children('label').on('click',function(event){
            var opt = $(this).parent(),
                chbox = opt.children('input'),
                val = chbox.val(),
                idx = opt.index();

            ($.inArray(val, obj.val) !== -1) ? obj.val.splice( $.inArray(val, obj.val), 1 ) : obj.val.push( val );
            ($.inArray(idx, obj.index) !== -1) ? obj.index.splice( $.inArray(idx, obj.index), 1 ) : obj.index.push( idx );
        });
    },
    getValue : function() {
        return this.val;
    },
    getIndex : function() {
        return this.index;
    }
}

$(function() {

    var dd = new DropDown( $('#dd') );

    $(document).click(function() {
        // all dropdowns
        $('.wrapper-dropdown-4').removeClass('active');
    });

});
//#131 Start By Luvina
$(function() {

	var dd = new DropDown( $('#dd2') );

	$(document).click(function() {
		// all dropdowns
		$('.wrapper-dropdown-3').removeClass('active');
	});

});
//#131 End By Luvina
$(document).ready(function() {
    /*
    *  Simple image gallery. Uses default settings
    */
    $('.fancybox').fancybox({
        wrapCSS    : 'fancybox-cocoyaku',
        padding : 15,
        margin : 10
    });
});
function getCookie(c_name) {
    var c_value = document.cookie;
    var c_start = c_value.indexOf(" " + c_name + "=");
    if (c_start == -1) {
        c_start = c_value.indexOf(c_name + "=");
    }
    if (c_start == -1){
        c_value = null;
    } else {
        c_start = c_value.indexOf("=", c_start) + 1;
        var c_end = c_value.indexOf(";", c_start);
        if (c_end == -1) {
            c_end = c_value.length;
        }
        c_value = unescape(c_value.substring(c_start,c_end));
    }
    return c_value;
}

function setCookie(c_name, value, exDays) {
    var date =  new Date();
    var exdate = new Date(date.getTime() + (exDays*24*60*60*1000));
    var c_value = escape(value) + ((exDays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}
var formSerialize = function(form_id){
	var values = {};
	if(form_id == '') return values; 
	var $inputs = $('#' + form_id + ' input, #' + form_id + ' textarea, #' + form_id + ' select');
	
	$inputs.each(function(i, el) {
		values[el.name] = $(el).val();
	});
	return values;
};

LOGIN_SUCCESS = 1;
function ajax_fancybox_request(params, name_action, uri){
	$(__el).unbind('click');
	$(__el).bind('click', function() {return false;});
	$.fancybox.showLoading();
	if(!params[name_action]) {
		params[name_action] = true;
	};
	// Ajax
	$.ajax({
		'type'    : "POST",
		'url'     : uri + "?" + name_action + '=true',
		'cache'   : false,
		'data'    : params,
		'success' : processResponeAsDone,
		'error'   : _notifyFailureAsAlert
	});
}
var _notifyFailureAsAlert = function(){
	$.fancybox.hideLoading();
	alert("An error occurred.");
	$(__el).bind('click', __call_back);
};
var _processResponeAsFancyboxPopup = function(response){
	if(response) {
		//#132 Start Luvina Modify
		try{
		$.fancybox({
            content : response,
            type    : 'ajax',
            wrapCSS : 'fancybox-cocoyaku',
            padding : 15,
            margin  : 10
        });
		} catch (e) {
			
		}
		//#132 End Luvina Modify
	}
	$(__el).bind('click', __call_back);
};
var processResponeAsDone = function(response) {
	if(response == LOGIN_SUCCESS){
		$.fancybox.close();
		$(__el).bind('click', __call_back);
		location.reload(true);
	} else {
		_processResponeAsFancyboxPopup(response);
		$.fancybox.hideLoading();
	}
};